<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <#assign base=request.contextPath  />
    <link rel="stylesheet" href="${base}/js/layui/css/layui.css?t=1534970980648" media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script src="${base}/js/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>

    <style type="text/css">
        form{
            padding:20px;
        }
        .layui-btn-radius{
            border-radius: 5px;
        }
    </style>
</head>
<body>
<form method="get" action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;角色</label>
            <div class="layui-input-block">
                <select name="city" lay-search="" lay-verify="required" id="roles">

                </select>
            </div>
        </div>
      <#-- <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;区域</label>
            <div class="layui-input-block">
                <select name="city" lay-search="" lay-verify="required" id="areaId">

                </select>
            </div>
        </div>-->
   <#-- <div class="layui-inline">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;指定</label>
        <div class="layui-input-block">
            <select name="city" lay-search="" lay-verify="required" id="appoint">
                <option value="可以">可以</option>
                <option value="不可以">不可以</option>
            </select>
        </div>
    </div>-->
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><a style="color:red">*</a>&nbsp;用户名</label>
                <div class="layui-input-inline">
                    <input name="number" lay-verify="required" autocomplete="off" class="layui-input" id="username"  type="text">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;密码</label>
            <div class="layui-input-inline">
                <input name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input " type="password">
            </div>
            <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;确认密码</label>
            <div class="layui-input-inline">
                <input name="password" placeholder="请输入密码" autocomplete="off" id="pass" class="layui-input" type="password">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-radius" lay-submit="" type="button" onclick="sub()" lay-filter=""style="background-color: #0092EF;">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary layui-btn-radius">重置</button>
            </div>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'layedit'], function(){
        var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit


    });
    findRole();
    //查询字典表状态
    var bas='${base}';
    var homeState=   getDataByCode(bas,"area");
    for(var i=0;i<homeState.length;i++){
        $("#areaId").append(
                '<option value="'+homeState[i].id+'">'+homeState[i].name+'</option>'
        )
    }

    function sub(){

        var isPass = document.getElementById("password").value;
        var reg=/^[a-z0-9_-]{6,18}$/;
        if(!reg.test(isPass)){
            layer.alert("必须是6-12位密码")
        }else if($("#pass").val()!=$("#password").val()){
            layer.alert("两次密码不匹配")
        }else{
            var requestData={};
            requestData.roleId=$("#roles").val();
            requestData.username=$("#username").val();
            requestData.password=$("#password").val();
            requestData.areaId=$("#areaId").val();
            //requestData.appoint=$("#appoint").val();


            $.ajax({
                type : "POST", //提交方式
                url : "${base}/user/insertUser",//路径
                data:{param:JSON.stringify(requestData)},
                success : function(data) {//返回数据根据结果进行相应的处理
                    layer.alert(data);
                    $(".renyuan").hide(200);

                    setTimeout(function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    },1200)


                    var table = layui.table;
                    //表刷新方法
                    table.reload('test', {
                        url: '${base}/user/userAdminList'
                        ,where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                }
            });
        }

    }


    function  findRole(){
        $.ajax({
            type : "POST", //提交方式
            url : "${base}/role/findRole",//路径
            success : function(data) {//返回数据根据结果进行相应的处理
                for(var i=0;i<data.data.length;i++){
                    $("#roles").append(
                            '<option value="'+data.data[i].id+'">'+data.data[i].roleName+'</option>'
                    )

                }
                layui.form.render();

            }
        });
    }
</script>
</body>

</html>
